#pragma rtGlobals=1		// Use modern global access method.

function convolution(fwhm,type)
Variable fwhm
String type
Wave func, Energy_y
Variable sigma = fwhm/(2*sqrt(2*log(2))), mu = 0

string savDF = GetDataFolder(1)
string folderDIR = DataFolderDir (1)
folderDIR = ReplaceString("FOLDERS:", folderDIR, "")
folderDIR = ReplaceString(",", folderDIR, ";")
variable i,j,n,q
	j = 0
	n = 0
	i = ItemsInList(folderDIR, ";")

Do
	
	string dataFolderName = stringFromList(j, folderDir, ";")
	Setdatafolder dataFolderName
	WaveStats/Q/Z Energy___ev
	Make/O/N=(V_npnts) func; SetScale x V_min, V_max, func
	func = exp(-((x-mu)^2)/(2*(sigma^2)))/(sigma*sqrt(2*pi))
	Make/O/N=(2*V_npnts) Energy_y
	SetScale x (2*V_min), (2*V_max), Energy_y
	Energy_y = x;
	String WaveDIR = WaveList("*",";","")
	WaveDir = ReplaceString("func;", WaveDir, "")
	WaveDir = ReplaceString("Energy___ev;", WaveDir, "")
	WaveDir = ReplaceString("Energy_y;", WaveDir, "")
	WaveDir = ReplaceString("_XAS", WaveDir, "")
	WaveDir = ReplaceString("_XES", WaveDir, "")
	WaveDir = ReplaceString("_conv", WaveDir, "")
	WaveDir = ReplaceString("_samp", WaveDir, "")
	q = ItemsInList(WaveDIR)
	n = 0
	Do
		string fullpath1 = savDF + dataFolderName + ":" + stringFromList(n, WaveDir, ";")
		string fullpath2 = fullpath1 + "_" + type
		Make/O/N=(V_npnts) $fullpath2
		WAVE w1 = $fullpath1
		WAVE w2 = $fullpath2
		w2 = w1
		DelayUpdate
		Convolve func, w2
		w2 = w2/sum(func)
		n += 1
	While(n < q)
Setdatafolder savDF
 j += 1
while(j < i-1)
 

end function